import { VuexModule, Module, Action, getModule } from 'vuex-module-decorators'
import { getRoomSorts, insertBatchRoomSort, deleteRoomSortOne } from '@/api/room_sort'
import store from '@/store'
import { IRoomSortModel } from '@/api/types'

export interface IRoomSortState {

}

@Module({ dynamic: true, store, name: 'RoomSort' })
class RoomSorts extends VuexModule implements IRoomSortState {

    @Action
    public async getRoomSorts(roomId?: string) {
        return new Promise((r: any, j: any) => {
            let data = roomId ? { roomId: roomId } : {}
            getRoomSorts(data).then((value: any) => {
                console.error("RoomSort:", value)
                r(value.data)
            }).catch(ex => {
                console.error(ex);
                j([])
            })
        })
    }

    @Action
    public async insertBatchRoomSort(list: Array<IRoomSortModel>) {
        return new Promise((r: any, j: any) => {
            let data = { Data: list }
            insertBatchRoomSort(data).then((value: any) => {
                console.error("RoomSort:", value)
                r(value.data)
            }).catch(ex => {
                console.error(ex);
                j([])
            })
        })
    }

    @Action
    public async deleteRoomSortOne(params: any) {
        return new Promise((r: any, j: any) => {
            let data = { Ids: params }
            deleteRoomSortOne(data).then((value: any) => {
                console.error("RoomSort:", value)
                r(value.data)
            }).catch(ex => {
                console.error(ex);
                j([])
            })
        })
    }

}

export const RoomSortModule = getModule(RoomSorts)
